package com.rui.study.micro.usermanager.entity;

import com.rui.study.commons.util.StringUtil;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.sql.Date;

@Data
public class UserInfo {

    private long userId;

    private Username username;

    private String password;

    private byte[] headPortraint;

    private Date createDate;

    private byte status;

    public UserInfo() {
    }

    /**
     * 内部类--用户名（邮箱，手机号，昵称）
     */
    @Data
    public static class Username {

        private String email;

        private String phoneNumber;

        private String name;

        public Username() {
        }

        @NotBlank(message = "Can not be blank")
        public Username(String principle) {
            if (StringUtil.isEmail(principle))
                this.email = principle;
            else if (StringUtil.isPhoneNumber(principle))
                this.phoneNumber = principle;
            else
                this.name = principle;
        }

        public Username(String email, String phoneNumber, String name) {
            this.email = email;
            this.phoneNumber = phoneNumber;
            this.name = name;
        }

        @Override
        public String toString() {
            String str;
            if (!StringUtil.isEmpty(email))
                str = email;
            else if (!StringUtil.isEmpty(phoneNumber))
                str = phoneNumber;
            else
                str = name;
            return str;
        }

    }
}

